package com.firmboy.beetl.hello.web;

import com.firmboy.beetl.hello.dao.AccountDao;
import com.firmboy.beetl.hello.model.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * web层
 *
 * @author firmboy
 * @create 2018-03-13 下午2:00
 **/
@RestController
@RequestMapping("/account")
public class AccountController {

    @Autowired
    private AccountDao accountDao;

    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public List<Account> getAll(){
        return accountDao.all();
    }

    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public Account findAccountById(@PathVariable("id") int id){
        Account single = accountDao.single(id);
        return single;
    }

    @RequestMapping(value = "/{id}",method = RequestMethod.DELETE)
    public int deleteById(@PathVariable("id") int id){
        int i = accountDao.deleteById(id);
        return i;
    }

}
